<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//展示页
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//查询
	if(!empty($_RQ['gameId'])){
		$params['gameId']=trim($_RQ['gameId']);
		$return['params']['gameId']=$params['gameId'];
	}if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$params['title'];
	}
	$fields=array('id','gameId','title','description','starttime','fileName','endtime','status','isShowJoinNum','isShowRegNum','award');
	$list=pdo_getslice('jy_h5game_reply',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			if(empty($item['status'])){
				$item['status'] = 1;
			}
			//不是数字，是老的数据
			if(!is_numeric($item['endtime']) || !is_numeric($item['starttime'])){
				pdo_update('jy_h5game_reply',array('starttime'=>intval(strtotime($item['starttime'])),'endtime'=>intval(strtotime($item['endtime']))),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
				if(time()>intval(strtotime($item['endtime']))){
					$item['status'] = 3;
				}
			}else{
				if(time()>$item['endtime']){
					$item['status'] = 3;
				}
				$item['starttime']=date('Y-m-d H:i',$item['starttime']);
				$item['endtime']=date('Y-m-d H:i',$item['endtime']);
			}
			
			$item['url']=custom_url('jy_h5game/welcome/reply/id='.$item['id'],true);
			if($this->pcgames[$item['fileName']]){
				$item['xianchangurl']=custom_url('jy_h5game/welcome/reply/os=window&id='.$item['id'],true);
				$item['xianchang']=1;
			}
			$gamename = pdo_getcolumn('core_h5game',array('name'=>$item['fileName']),'title');
			$item['gamename']=$gamename ? $gamename : $item['fileName'];
			//是否绑定商城
			$item['shopgametitle']=pdo_getcolumn('jy_weishop_game',array('game_id'=>$item['id']),'title');
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list?$list:array();
	$htmls=array(
		array('type' =>'list',
			'tabs'=>array(
				array('op'=>'list','title'=>'管理活动'),
				array('action'=>'hdgame','title'=>'添加活动'),
			),
			'list' =>array ('data' => 'list','tip'=>'【温馨提示】；每个游戏的设置是全局的：就是所有的游戏设置的内容都是差不多的。所以不是所有设置的功能都是用的上的。</br>1、部分游戏是不支持奖品，抽奖这些功能的；</br>2、只有少部分游戏是支持自定义设置的，大部分游戏这列是空的；</br>3、所有<red>现场类</red>的互动游戏，是没有手机端的，只能电脑端访问，可能预览的时候会有差异！</br>4、<red>商城系绑定某游戏后，该游戏就无法正常参与，只有满足商城的条件才能参与！</red>','list' => array(
				array('title' => '活动名称','name' => 'title', 'type' => 'string'),
		        array('title' => '游戏名称','name' => 'gamename','type' => 'string'),
				array ('title' => '活动链接','name' => 'url','type' => 'copy'),
				array ('title' => '已绑定商城活动','name' => 'shopgametitle','type' => 'string'),
		        array('type'=>'img_string','title'=>'活动时间',
						'data'=>array(
							array('title'=>'开始时间：','name'=>'starttime'),
							array('title'=>'结束时间：','name'=>'endtime')
							)
				),
		        array ('title' => '活动状态','name' => 'status','type' => 'radio','options' => 'status_xuanxiang',),
				array ('title' => '活动链接','name' => 'url','type' => 'copy',),
				array ('title' => '活动二维码','name' => 'url','type' => 'ewm', ),
				),
			   'delall' => true,
		       'del_one' => true,
		       'edit' => true,
		'action' => 
				array (
				   array('type'=>'href_blank','name' => 'xianchangurl','title'=>'现场大屏','show'=>array('xianchang'=>1)),
			       array('type'=>'post','op'=>'publish','title'=>'发布','message'=>'确定发布该活动吗！','show'=>array('status'=>1)),
			       array('type'=>'post','op'=>'over','title'=>'结束','message'=>'确定结束该活动吗！','show'=>array('status'=>2)),
				   array('type'=>'post','op'=>'uptwo','title'=>'重新开始','message'=>'确定重启该活动吗！','show'=>array('status'=>3)),
		           array ('title' => '预览','type' => 'modal','op'=>'yulan'),
		           array ('title' => '获奖名单',),
		           array ('title' => '传播数据',),
		           array ('title' => '渠道','type' => 'modal','op'=>'qudao'),
				),
		 ),
		'search_one' => 
		  array ( 'name' => 'title','add' => false),
		   ),
	     );
	$return['htmls']=$htmls;
	$return['status_xuanxiang']=array (1 => '未发布',2 => '进行中',3=>'已结束');
	exi($return);
}
//编辑页
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array_fields(array (0 => 'title', 1 => 'description'),$post);
		$id=intval($post['id']);
		if($id){
			$this->update('reply',$data,array('id'=>$id));
			exi('修改活动成功！','','list');
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['createtime']=TIMESTAMP;
			$this->insert('reply',$data);
			exi('新增活动成功！','','list');
		}
	}else{
		$id=intval($_RQ['id']);
		if($id){
			$item=$this->get('reply',array('id'=>$id));
			$gameinfo = pdo_get('core_h5game',array('name'=>$item['fileName']),array('title','type','diy_form'));
			$item['diy_form2']=json_decode($gameinfo['diy_form'],true);
			$item['diy_form']=$item['diy_form']?json_decode($item['diy_form'],true):array();
		//	$item['award']['cashTime']=json_decode($item['award']['cashTime'],true);
		}else{
			$item=array();
			$item['award']=array();
			$item['award']['0']=array();
			if(empty($_RQ['name'])){
				exi('没有选择游戏！','error');
			}else{
				$item['fileName']=$_RQ['name'];
			}
			$gameinfo = pdo_get('core_h5game',array('name'=>$item['fileName']),array('title','type','diy_form'));
			$item['title']=$gameinfo['title'] ? $gameinfo['title'] : $item['fileName'];
			$item['diy_form2']=json_decode($gameinfo['diy_form'],true);
			$item['diy_form']=array('default'=>'');
			if($item['fileName']=='koi'){
				$item['award']=ijson_encode(array(array('prizeImg'=>'../addons/jy_h5game/custom/templates/mobile/games/koi/images/zWz82NHUZW.png','prizeName'=>'锦鲤大礼包','prizeLevel'=>'锦鲤奖')));
			}
		}
		if($gameinfo['type'] != 5){
			$item['game_show']=5;
		}
		if(!is_int($item['starttime'])){
			$item['starttime']=$item['starttime']?:time()-1000;
			$item['starttime']=date('Y-m-d H:i',$item['starttime']);
			$item['endtime']=$item['endtime']?:time()+3600*24*7;
			$item['endtime']=date('Y-m-d H:i',$item['endtime']);
		}
		$item['type']=$gameinfo['type'];
		$return['item']=$item;
		$return['item']['award']=json_decode($return['item']['award']);
		$return['isShowRegNum']=array('1'=>'隐藏','2'=>'展示');
		$return['isLimitRegNum']=array('1'=>'限制','2'=>'不限制');
		$return['forFansOnly']=array('1'=>'开启','2'=>'关闭');
		$return['forAdvertising']=array('1'=>'隐藏','2'=>'展示');
		$return['isshare']=array('1'=>'开启','2'=>'关闭');
		$return['iswxshare']=array('1'=>'默认','2'=>'自定义');
		$return['isShowLogo']=array('1'=>'默认','2'=>'自定义');
		if($gameinfo['type'] == 7){
			$return['gameTypeSetting']=array('1'=>'抽奖派发');
		}else{
			$return['gameTypeSetting']=array('1'=>'抽奖派发','2'=>'参与送券','3'=>'按排名派发','4'=>'报名后派发');
		}
		$return['isLimitDrawTimes']=array('1'=>'限制','2'=>'不限');
		$return['repartDarw']=array('1'=>'开启','2'=>'关闭');
		$return['helpType']=array('1'=>'分享奖励','2'=>'邀请奖励','关闭');
		$return['linkInfotype']=array('1'=>'参与前填写','2'=>'抽奖前填写','3'=>'中奖后填写','4'=>'关闭');
		$return['linkInfotype2']=array('1'=>'参与前填写','2'=>'参与后填写');
		$return['isShowLogo']=array('1'=>'开启','2'=>'关闭');
		$return['isLoadingImage']=array('1'=>'默认','2'=>'自定义');
		$return['menuStyle']=array('1'=>'隐藏','2'=>'页面跳转','3'=>'一键关注');
		$return['isShowSkillSup']=array('1'=>'隐藏','2'=>'显示');
		$return['isUnit']=array('1'=>'默认','2'=>'自定义');
		$return['isShowSlide']=array('1'=>'关闭','2'=>'开启');
		$return['openAreaLimit']=array('1'=>'全部','2'=>'部分');
		$return['isCuctomTime']=array('1'=>'默认','2'=>'自定义');
		$return['isRank']=array('1'=>'默认','2'=>'自定义');
		$return['cashStyle']=array('1'=>'线下兑奖','2'=>'邮寄方式','3'=>'系统线上发放');
		$return['prizeType']=array('1'=>'实物','2'=>'积分','3'=>'卡券','4'=>'现金红包');
		if($gameinfo['type'] == 7){
			$return['prizeType']=array('4'=>'现金红包');
		}else{
			$return['prizeType']=array('1'=>'实物','2'=>'积分','3'=>'卡券');
		}
		$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edit_tab'=>true,
		'tip'=>'当前游戏可能不需要设置某些参数，请按需设置！',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'管理活动'),
		),
		'edits'=>array(
			'0'=>array(
				'title'=>'基础设置',
				'list'=>array(
					array('type'=>'tip','title'=>'<red>[温馨提示]：当前游戏可能不需要设置某些参数，请按需设置！</red>'),
					array('type'=>'string','title'=>'活动标题','name'=>'title',),
					array('type'=>'string','title'=>'绑定的游戏','name'=>'fileName','read'=>true),
					array('type'=>'time','title'=>'开始时间','name'=>'starttime',),
					array('type'=>'time','title'=>'结束时间','name'=>'endtime',),
					array('type'=>'radio','title'=>'参与人数','name'=>'isShowRegNum','options'=>'isShowRegNum',),
					array('type'=>'string','title'=>'虚拟参与人数','name'=>'virtualRegNum','help'=>'在实际参与活动的人数上增加的人数，仅展示，不计入统计','show'=>array('isShowRegNum'=>2)),
					array('type'=>'radio','title'=>'参与人数限制','name'=>'isLimitRegNum','options'=>'isLimitRegNum'),
					array('type'=>'string','title'=>'限制参与人数','name'=>'virtualRegNum_new','help'=>'','show'=>array('isLimitRegNum'=>1)),
				//	array('type'=>'radio','title'=>'强制关注','name'=>'forFansOnly','options'=>'forFansOnly',),
					array('type'=>'switch','title'=>'不显示奖品信息？','name'=>'noshow_award','help'=>'满足部分场景，不需要显示奖品信息，获奖信息的需求！'),
					array('type'=>'radio','title'=>'广告页','name'=>'forAdvertising','options'=>'forAdvertising',),
					array('type'=>'text','title'=>'活动说明','name'=>'content',),
				)
			),
			'1'=>array(
				'title'=>'派奖方式',
				'show'=>array('game_show'=>5),
				'list'=>array(
					array('type'=>'tip','title'=>'<red>[温馨提示]：当前游戏可能不需要设置某些参数，请按需设置！</red>'),
					array('type'=>'radio','title'=>'派奖方式','name'=>'gameTypeSetting','options'=>'gameTypeSetting','help'=>'抽奖活动请选择‘抽奖派发’模式'),
					array('type'=>'string','title'=>'抽奖门槛','name'=>'drawTotal','help'=>'<red>只有部分带有游戏积分的活动才支持，不带游戏积分的，本设置无效！</red>游戏成绩达到该门槛，即为挑战成功可抽奖','show'=>array('gameTypeSetting'=>1,)),
				  //array('type'=>'radio','title'=>'快捷重复抽奖','name'=>'repartDarw','options'=>'repartDarw','show'=>array('gameTypeSetting'=>1),'help'=>'开启后，玩家抽奖后若不中奖可直接点击继续抽奖（无需重复参与游戏）'),
					array('type'=>'radio','title'=>'每人总抽奖机会','name'=>'isLimitDrawTimes','options'=>'isLimitDrawTimes','show'=>array('gameTypeSetting'=>1),'help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'string','title'=>'每人总抽奖机会','name'=>'playTotalLimit','show'=>array('gameTypeSetting'=>1,'isLimitDrawTimes'=>1),'help'=>'本游戏参与商城活动后，本设置无效！'),
				  //array('type'=>'string','title'=>'每日抽奖机会','name'=>'playTimesLimit','show'=>array('gameTypeSetting'=>1)),
					array('type'=>'string','title'=>'每人中奖次数','name'=>'awardTimesLimit','show'=>array('gameTypeSetting'=>1),'help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'radio','title'=>'好友助力','name'=>'helpType','show'=>array('gameTypeSetting'=>1),'options'=>'helpType'),
					array('type'=>'radio','title'=>'联系信息','name'=>'linkInfotype','show'=>array('gameTypeSetting'=>1),'options'=>'linkInfotype'),				
					array('type'=>'string','title'=>'领取门槛','name'=>'drawTotal','help'=>'<red>本游戏参与商城活动后，本设置无效！只有部分带有游戏积分的活动才支持，不带游戏积分的，本设置无效！</red>游戏成绩达到该门槛，即为挑战成功可领取礼品','show'=>array('gameTypeSetting'=>2,)),
				    array('type'=>'radio','title'=>'联系信息','name'=>'linkInfotype','show'=>array('gameTypeSetting'=>2),'options'=>'linkInfotype'),
					
					array('type'=>'radio','title'=>'总参与机会','name'=>'isLimitDrawTimes','options'=>'isLimitDrawTimes','show'=>array('gameTypeSetting'=>3),'help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'string','title'=>'总参与机会','name'=>'playTotalLimit','show'=>array('gameTypeSetting'=>3,'isLimitDrawTimes'=>1),'help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'string','title'=>'每日参与机会','name'=>'playTimesLimit','show'=>array('gameTypeSetting'=>3),'help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'radio','title'=>'好友助力','name'=>'helpType','show'=>array('gameTypeSetting'=>3),'options'=>'helpType','help'=>'本游戏参与商城活动后，本设置无效！'),
					array('type'=>'radio','title'=>'联系信息','name'=>'linkInfotype','show'=>array('gameTypeSetting'=>3),'options'=>'linkInfotype2'),
					
					array('type'=>'string','title'=>'报名门槛','name'=>'drawTotal','help'=>'游戏成绩达到该门槛，即为挑战成功可报名','show'=>array('gameTypeSetting'=>4,)),
					array('type'=>'radio','title'=>'联系信息','name'=>'linkInfotype','show'=>array('gameTypeSetting'=>4),'options'=>'linkInfotype'),
				)
			),
			'2'=>array(
				'title'=>'奖项设置',
				'show'=>array('game_show'=>'5'),
				'list'=>array(
					array('type'=>'tip','title'=>'[<red>温馨提示</red>]：奖品的图片必须是正方形，否则一些地方显示会异常；比如：九宫格游戏！','name'=>'prizeName'),
				/*	array('type'=>'string','title'=>'兑奖地址','name'=>'cashPlace'),
					array('type'=>'string','title'=>'操作提示','name'=>'operation'),
					array('type'=>'time','title'=>'兑奖期限','name'=>'cashTime'),
					array('type'=>'string','title'=>'兑奖须知','name'=>'cashInfo'), */
					array('type'=>'switch','title'=>'现金红包？','name'=>'redtype','show'=>array('type'=>7),'help'=>'默认是余额红包，可以在会员中心可见红包，进行提现消费等，这样可以支持小于1元的红包，如果开现金红包，就是直接打款到客户微信零钱钱包'),
					array(
					'type'=>'array',
					'name'=>'award',
					'add_tip'=>'添加一个奖项',
						'list'=>array(
							array('type'=>'string','title'=>'奖品名称','name'=>'prizeName'),
							array('type'=>'radio','title'=>'奖品类型','name'=>'prizeType','help'=>'','options'=>'prizeType'),
							array('type'=>'string','title'=>'红包总金额','name'=>'hbSum','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'单个红包最小金额','name'=>'hbLow','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'单个红包最大金额','name'=>'hbHigh','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'奖励积分','name'=>'jifen','show'=>array('prizeType'=>'2')),
							array('type'=>'string','title'=>'奖品等级','name'=>'prizeLevel'),
							array('type'=>'string','title'=>'奖品数量','name'=>'prizeNum'),
							array('type'=>'string','title'=>'中奖概率','name'=>'rate'),
							array('type'=>'image','title'=>'奖品图片','name'=>'prizeImg'),
							array('type'=>'radio','title'=>'兑奖方式','name'=>'cashStyle','options'=>'cashStyle'),
							array('type'=>'string','title'=>'兑奖地址','name'=>'cashPlace'),
							array('type'=>'string','title'=>'操作提示','name'=>'operation'),
							array('type'=>'string','title'=>'兑奖期限','name'=>'cashTime'),
							array('type'=>'string','title'=>'兑奖须知','name'=>'cashInfo'),
							
						),
						'details'=>array(
							array('type'=>'string','title'=>'奖品名称','name'=>'prizeName'),
							array('type'=>'radio','title'=>'奖品类型','name'=>'prizeType','help'=>'','options'=>'prizeType'),
							array('type'=>'string','title'=>'奖励积分','name'=>'jifen','show'=>array('prizeType'=>'2')),
							array('type'=>'string','title'=>'红包总金额','name'=>'hbSum','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'单个红包最小金额','name'=>'hbLow','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'单个红包最大金额','name'=>'hbHigh','show'=>array('prizeType'=>'4')),
							array('type'=>'string','title'=>'奖品等级','name'=>'prizeLevel'),
							array('type'=>'unitstring','title'=>'奖品数量','name'=>'prizeNum','show'=>array('prizeType'=>'1'),'unit'=>'个/只'),
							array('type'=>'unitstring','title'=>'奖品数量','name'=>'prizeNum','show'=>array('prizeType'=>'2'),'unit'=>'个/只'),
							array('type'=>'unitstring','title'=>'奖品数量','name'=>'prizeNum','show'=>array('prizeType'=>'3'),'unit'=>'个/只'),
							array('type'=>'unitstring','title'=>'中奖概率','name'=>'rate','unit'=>'%'),
							array('type'=>'image','title'=>'奖品图片','name'=>'prizeImg'),
							array('type'=>'time_range','title'=>'兑奖期限','name'=>'cashTime'),
							array('type'=>'radio','title'=>'兑奖方式','name'=>'cashStyle','options'=>'cashStyle'),
							array('type'=>'string','title'=>'兑奖地址','name'=>'cashPlace'),
							array('type'=>'string','title'=>'操作提示','name'=>'operation'),
							array('type'=>'string','title'=>'兑奖须知','name'=>'cashInfo'),
						)
				),
					
				)
			),
			'3'=>array(
				'title'=>'活动分享设置',
				'show'=>array('game_show'=>5),
				'list'=>array(
					array('type'=>'tip','title'=>'<red>[温馨提示]：当前游戏可能不需要设置某些参数，请按需设置！</red>'),
					array('type'=>'radio','title'=>'分享设置','name'=>'isshare','options'=>'isshare','help'=>''),
					array('type'=>'radio','title'=>'微信分享图标','name'=>'isShowLogo','options'=>'isShowLogo','help'=>''),
					array('type'=>'image','title'=>'分享图标','name'=>'logo','show'=>array('isShowLogo'=>'1')),
					//array('type'=>'radio','title'=>'微信分享内容','name'=>'iswxshare','options'=>'iswxshare',),	
					array('type'=>'text','title'=>'分享内容','name'=>'share',)
				)
			),
			'4'=>array(
				'title'=>'企业信息',
				'show'=>array('game_show'=>5),
				'list'=>array(
					array('type'=>'tip','title'=>'<red>[温馨提示]：当前游戏可能不需要设置某些参数，请按需设置！</red>'),
					array('type'=>'string','title'=>'主办单位','name'=>'hostname','help'=>''),
					array('type'=>'string','title'=>'企业链接','name'=>'hostlink','help'=>''),
					array('type'=>'radio','title'=>'企业logo','name'=>'isShowLogo','options'=>'isShowLogo','help'=>''),
					array('type'=>'image','title'=>'logo','name'=>'logo','help'=>'','show'=>array('isShowLogo'=>'1')),
					array('type'=>'radio','title'=>'页面加载图片','name'=>'isLoadingImage','help'=>'','options'=>'isLoadingImage'),
					array('type'=>'image','title'=>'页面加载图片','name'=>'loadingImage','help'=>'','show'=>array('isLoadingImage'=>'2')),
					array('type'=>'radio','title'=>'功能按钮','name'=>'menuStyle','help'=>'','options'=>'menuStyle'),
					array('type'=>'string','title'=>'按钮名称','name'=>'menuName','help'=>'','show'=>array('menuStyle'=>'2')),
					array('type'=>'string','title'=>'按钮链接','name'=>'menuLink','help'=>'','show'=>array('menuStyle'=>'2')),
					array('type'=>'string','title'=>'按钮名称','name'=>'menuName','help'=>'','show'=>array('menuStyle'=>'3')),
					array('type'=>'image','title'=>'微信公众号二维码','name'=>'qrcode','help'=>'','show'=>array('menuStyle'=>'3')),
					
				)
			),
			'5'=>array(
				'title'=>'游戏设置',
				'show'=>array('game_show'=>5),
				'list'=>array(
					array('type'=>'tip','title'=>'<red>[温馨提示]：当前游戏可能不需要设置某些参数，请按需设置！</red>'),
				    array('type'=>'radio','title'=>'排行榜','name'=>'isRank','help'=>'排行榜展示前xx名，默认展示前30','options'=>'isRank'),
					array('type'=>'string','title'=>'排行榜','name'=>'rank','help'=>'','show'=>array('isRank'=>'2')),
					array('type'=>'radio','title'=>'广告','name'=>'isShowSkillSup','help'=>'','options'=>'isShowSkillSup'),
					array('type'=>'string','title'=>'广告','name'=>'skillSup','help'=>'','show'=>array('isShowSkillSup'=>'2')),
					array('type'=>'radio','title'=>'分数单位','name'=>'isUnit','options'=>'isUnit','help'=>''),
					array('type'=>'string','title'=>'分数单位','name'=>'unit','help'=>'','show'=>array('isUnit'=>'2')),
					array('type'=>'radio','title'=>'游戏时间','name'=>'isCuctomTime','help'=>'','options'=>'isCuctomTime'),
					array('type'=>'string','title'=>'游戏时间','name'=>'cuctomTime','help'=>'','show'=>array('isCuctomTime'=>'2')),
					array('type'=>'radio','title'=>'轮播获奖信息','name'=>'isShowSlide','help'=>'','options'=>'isShowSlide'),
					array('type'=>'text','title'=>'轮播获奖信息','name'=>'slide','help'=>'','show'=>array('isShowSlide'=>'2')),
					array('type'=>'image','title'=>'活动背景图','name'=>'backpicurl','help'=>'尺寸：宽640*1010；部分活动支持自定义背景图'),
				  //array('type'=>'radio','title'=>'可参与地区','name'=>'openAreaLimit','help'=>'','options'=>'openAreaLimit'),
				  //array('type'=>'string','title'=>'可参与地区','name'=>'openArea','help'=>'','show'=>array('openAreaLimit'=>'2')),
				)
			),
			'6'=>array(
				'title'=>'自定义设置',
				'tovalue'=>'diy_form',
				'list'=>$item['diy_form2'],
			),
			),
			
	);
	$return['htmls']=$htmls;
	exi($return);
}
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
    //$postdata['award']['cashTime'] = ijson_encode($postdata['award']['cashTime']);	
	//exi(ijson_encode($postdata['award']['prizeName'],'error'));
	if(!$postdata['starttime']){
		exi('请设置活动开始时间','error');
	}
	if(!$postdata['endtime']){
		exi('请设置活动结束时间','error');
	}
	if(!$postdata['gameTypeSetting']){
		//exi('请设置活动派奖方式','error');
	}
	$sum=0;
	if($postdata['award']){
		foreach($postdata['award'] as &$row){
			$row['rate']=round($row['rate']*1,2);
			$sum+=$row['rate'];
		}
	}
	if($sum && $sum!=100){
			exi('奖品中奖概率之和必须等于100，请检查并重新设置！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'fileName'=>trim($postdata['fileName']),
		'isShowRegNum'=>trim($postdata['isShowRegNum']),
		'virtualRegNum'=>trim($postdata['virtualRegNum']),
		'starttime'=>strtotime($postdata['starttime']),
		'endtime'=>strtotime($postdata['endtime']),
		'isLimitRegNum'=>trim($postdata['isLimitRegNum']),
		'award'=>ijson_encode($postdata['award']),
		'virtualRegNum_new'=>trim($postdata['virtualRegNum_new']),
		'forFansOnly'=>trim($postdata['forFansOnly']),
		'forAdvertising'=>trim($postdata['forAdvertising']),
		'content'=>trim($postdata['content']),
		'gameTypeSetting'=>trim($postdata['gameTypeSetting'])?:1,
		'drawTotal'=>trim($postdata['drawTotal']),
		'isLimitDrawTimes'=>trim($postdata['isLimitDrawTimes']),
		'playTimesLimit'=>trim($postdata['playTimesLimit']),
		'winningRate'=>trim($postdata['winningRate']),
		'helpType'=>trim($postdata['helpType']),
		'linkInfotype'=>trim($postdata['linkInfotype']),
		'isshare'=>trim($postdata['isshare']),
		'isShowLogo'=>trim($postdata['isShowLogo']),
		'logo'=>trim($postdata['logo']),
		'isshare'=>trim($postdata['isshare']),
		'iswxshare'=>trim($postdata['iswxshare']),
		'share'=>trim($postdata['share']),
		'hostname'=>trim($postdata['hostname']),
		'hostlink'=>trim($postdata['hostlink']),
		'isLoadingImage'=>trim($postdata['isLoadingImage']),
		'loadingImage'=>trim($postdata['loadingImage']),
		'menuName'=>trim($postdata['menuName']),
		'menuStyle'=>trim($postdata['menuStyle']),
		'menuLink'=>trim($postdata['menuLink']),
		'qrcode'=>trim($postdata['qrcode']),
		'isShowSkillSup'=>trim($postdata['isShowSkillSup']),
		'isUnit'=>trim($postdata['isUnit']),
		'unit'=>trim($postdata['unit']),
		'isCuctomTime'=>trim($postdata['isCuctomTime']),
		'cuctomTime'=>trim($postdata['cuctomTime']),
		'isShowSlide'=>trim($postdata['isShowSlide']),
		'slide'=>trim($postdata['slide']),
		'openAreaLimit'=>trim($postdata['openAreaLimit']),
		'openArea'=>trim($postdata['openArea']),
		'isRank'=>trim($postdata['isRank']),
		'awardTimesLimit'=>trim($postdata['awardTimesLimit']),
		'playTotalLimit'=>trim($postdata['playTotalLimit']),
		'rank'=>trim($postdata['rank']),
		'diy_form'=>ijson_encode($postdata['diy_form']),
		'redtype'=>intval($postdata['redtype']),
		'backpicurl'=>trim($postdata['backpicurl']),
		'noshow_award'=>intval($postdata['noshow_award']),
	);
	$id=intval($postdata['id']);
	if($id){
		$this->update('reply',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			exi('更新成功！','','list');
	}
	else{
			$data['uniacid']=$_SESSION['uniacid'];
			$this->insert('reply',$data);
			$id=pdo_insertid();				
			exi('添加活动成功！','','list');
	}
}
if($_RQ['op']=='del'){
	
	$id=intval($_RQ['id']);

	if($id){
		$this->delete('reply',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('reply',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
  }
  //发布活动
  if($_RQ['op']=='publish'){
	
	$id=intval($_RQ['id']);
	if($id){
		$this->update('reply',array('status'=>2),array('id'=>$id));	
	}

	exi('成功发布！');
  }
if($_RQ['op']=='over'){
	
	$id=intval($_RQ['id']);
	if($id){
		$this->update('reply',array('status'=>3),array('id'=>$id));	
	}

	exi('活动已结束！');
}
if($_RQ['op']=='uptwo'){
	
	$id=intval($_RQ['id']);
	if($id){
		$this->update('reply',array('status'=>2),array('id'=>$id));	
	}

	exi('重启活动成功！');
}
  if($_RQ['op']=='qudao'){
	  $id=intval($_RQ['id']);
	  $item['fansum']=pdo_count('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	  $item['saosum']=pdo_count('jy_h5game_fans',array('rid'=>$id,'fromchannel'=>'sao','uniacid'=>$_SESSION['uniacid']));
	  $item['sharesum']=pdo_count('jy_h5game_fans',array('rid'=>$id,'fromchannel'=>'share','uniacid'=>$_SESSION['uniacid']));
	  $item['urlsum']=pdo_count('jy_h5game_fans',array('rid'=>$id,'fromchannel'=>'url','uniacid'=>$_SESSION['uniacid']));
		$pindex = max(1, intval($_RQ['page']));
		$psize = 1;
		$total='';
		$params=array('rid'=>$id,'uniacid'=>$_SESSION['uniacid']);
		$fields=array('id','bestScore');
		$list=pdo_getslice('jy_h5game_fans',$params,array($pindex,$psize),$total,$fields,'','bestScore desc');
	   $item['maxscore']=$list[0]['bestScore']?:0;
	  $htmls=array(
		'type'=>'look',
		'desc'=>'渠道数据',
		'look'=>array(
			array('type'=>'string','title'=>'玩家数量','name'=>'fansum','read'=>true),
			array('type'=>'string','title'=>'最高得分','name'=>'maxscore','read'=>true),
			array('type'=>'string','title'=>'扫码来源','name'=>'saosum','read'=>true),
			array('type'=>'string','title'=>'分享来源','name'=>'sharesum','read'=>true),
			array('type'=>'string','title'=>'网址来源','name'=>'urlsum','read'=>true),
		)
	);
	$return['item']=$item;
	$return['htmls']=$htmls;
	exi($return);
  }
if($_RQ['op']=='yulan'){
	   $id=intval($_RQ['id']);
	   $follow=1;
	   $item=$this->get('reply',array('id'=>$id));
	   $return['linkurl']=custom_url('jy_h5game/welcome/reply/os=mobile&id='.$id,true);
	   $return['title']=$item['title'];
	   $return['htmls']=file_get_contents(ADDONS.'/jy_h5game/manage/templates/windows/list.html');
	   exi($return);
}
